home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / swags-z / sorting.swg / 0028_SORT-PTR.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  1KB  |  41 lines

  1. {
  2.    This is using the concept of a PoINter Array (an Array of PoINters).  It
  3. allows For a _very_ large amount of data, sINce you allocate each Record space
  4. of the Heap.  You must allocate each space For each Record as you create the
  5. Record:
  6. }
  7.  
  8.   New (INFOSTUFF[3]);  { allocates space For 3rd Record }
  9.   With INFOSTUFF[6]^ do  { works With 6th Record }
  10.     begin
  11.       NAME := 'Patrick Edwards'; IDNUM := 60000; MOM := ''
  12.     end;
  13.  
  14.    The sort could be:
  15.  
  16. Var T : INFO;
  17. Procedure L_HSorT (LEFT,RIGHT : Word);      { Lo-Hi QuickSort }
  18. Var LOWER,UPPER,MIDDLE : Word;
  19.     PIVOT              : INFO;
  20. begin
  21.   LOWER := LEFT; UPPER := RIGHT; MIDDLE := (LEFT+RIGHT) div 2;
  22.   PIVOT := INFOSTUFF[MIDDLE]^;
  23.   Repeat
  24.     While INFOSTUFF[LOWER]^.NAME < PIVOT.NAME do INc(LOWER);
  25.     While PIVOT.NAME < INFOSTUFF[UPPER]^.NAME do Dec(UPPER);
  26.     if LOWER <= UPPER then
  27.       begin
  28.         T := INFOSTUFF[LOWER]^; INFOSTUFF[LOWER]^ := INFOSTUFF[UPPER]^;
  29.         INFOSTUFF[UPPER]^ := T;
  30.         INc (LOWER); Dec (UPPER);
  31.       end;
  32.   Until LOWER > UPPER;
  33.   if LEFT < UPPER then L_HSorT (LEFT, UPPER);
  34.   if LOWER < RIGHT then L_HSorT (LOWER, RIGHT);
  35. end;                                                { L_HSorT }
  36.  
  37. {   called as:
  38.  
  39. L_HSorT (1,10);
  40. }
  41.